<?php
use Doraemon\tools\ImgUrl as toolImgUrl;
use Hhzbeads\Img\ImgUpload;

class UploadFilesAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $file = $_FILES["file_data"]["tmp_name"];
        $picId = ImgUpload::upload(ImgUpload::APPTYPE_BIZ, $file);
        if (is_array($picId) && !empty($picId)) {

            $result = [
                "picId" => $picId["ori_pic_id"],
                'url' => toolImgUrl::getUrl(toolImgUrl::APPTYPE_BIZ, $picId['ori_pic_id'], toolImgUrl::IMAGE_SIZE_SQ_PHONE),
                'thumb_url' => toolImgUrl::getUrl(toolImgUrl::APPTYPE_BIZ, $picId['ori_pic_id'], toolImgUrl::IMAGE_SIZE_SQ_THUMB)
            ];

            $this->setSuccess($result);
        } else {
            throw new \Exception('上传失败');
        }
    }
}